<template>
	<view class="u-page">
		<view class="u-demo-block">
			<u--form
				:labelWidth="80"
				:model="formData"
				:rules="formRules"
				ref="form">
				<!-- 输入账户 -->
				<u-form-item
					label="账户号"
					required
					prop="userInfo.userCode">
					<u-input
						v-model="formData.userCode"
						:disabled="true">
					</u-input>				
				</u-form-item>
				<!-- 输入设备 -->
				<u-form-item
					label="设备号"
					required
					prop="machineInfo.machineNo">
					<u-input
						v-model="formData.machineNo"
						:disabled="true">
					</u-input>				
				</u-form-item>
				<!-- 作业项目 -->
				<u-form-item
					label="作业项目"
					prop="opItemName"
					required>
					<u-input
						v-model="formData.opItemName"
						disabled
						fontSize="13px"
						color="#12569F">
					</u-input>
				</u-form-item>
				<!-- 作业记录结果 -->
				<u-form-item
					:label="formItemRecordLabel"
					prop="recordValue"
					ref="recordItem">
					<!-- 文本域 -->
					<u--textarea
						v-model="formData.recordValue"
						v-show="show.formItemShow.recordItemInner.textarea"
						autoHeight
						count
						:maxlength="144">
					</u--textarea>
					<!-- input输入框 -->
					<u-input
						v-model="formData.recordValue"
						v-show="show.formItemShow.recordItemInner.input"
						clearable	
						@focus="hideKeyboard"
						@blur="textInputItemBlur">
					</u-input>
					<!-- 单选框 -->
					<u-radio-group
						v-show="show.formItemShow.recordItemInner.radio"
						v-model="formData.recordValue"
						placement="column"
						@change="radioChange">
						<u-radio
							v-for="(item,index) in selectedOpItemPojo.opItemContent"
							:key="index"
							:label="item"
							:name="item"
							:customStyle="{marginLeft:'80px',marginBottom: '10px'}">
							
						</u-radio>
					</u-radio-group>
					<!-- 多选框 -->
					<u-checkbox-group
						v-show="show.formItemShow.recordItemInner.checkbox"
						v-model="checkboxOpRecordValueArr"
						placement="column"
						@change="checkboxChange">
						<u-checkbox
							v-for="(item,index) in selectedOpItemPojo.opItemContent"
							:key="index"
							:label="item"
							:name="item"
							:customStyle="{marginLeft:'80px',marginBottom: '10px'}">
							
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<view class="echo">
					<u--text
						type="success"
						wordWrap="break-word"
						:lines="2"
						:text="echo.qrPn"
						:customStyle="{marginBottom:'8px'}">
					</u--text>
					<u--text
						type="success"
						wordWrap="break-word"
						:lines="2"
						:text="echo.qrLotNo">
					</u--text>
				</view>
				
				<!-- 异常处置 -->
				<u-form-item
					v-show="show.formItemShow.abHandle"
					label="异常处置"
					prop="abHandleValue"
					ref="abHandleItem">
				
					<!-- 多选框 -->
					<u-checkbox-group
						v-model="checkboxAbHandleValueArr"
						placement="column"
						@change="checkboxAbHandleChange">
						<!-- 多选 -->
						<u-checkbox
							v-for="(item,index) in selectedOpItemPojo.abHandleList"
							:key="index"
							:label="item"
							:name="item"
							:customStyle="abHandleCustomStyle">
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				
				<!-- 记录开始时间 -->
				<u-form-item
					label="记录开始\n时间"
					required
					prop="timeInfo.begin"
					ref="timeInfoBegin"
					@click="show.timePicker.begin=true">
					<u-input
						v-model="formData.timeInfo.begin"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择记录开始时间"
						fontSize="13px"
						color="#12569F">
					</u-input>
				</u-form-item>
				<u-form-item
					label="记录结束\n时间"
					required
					prop="timeInfo.end"
					ref="timeInfoEnd"
					@click="show.timePicker.end=true">
					<u-input
						v-model="formData.timeInfo.end"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择记录结束时间"
						fontSize="13px"
						color="#12569F">
					</u-input>
				</u-form-item>
				
				<!-- 输入选择列 -->
				<u-form-item
					v-show="show.columnsNo"
					label="选择列"
					prop="checkboxColumnsNoArr"
					ref="columnNo">
					<u-checkbox-group
						v-model="formData.checkboxColumnsNoArr"
						placement="column"
						@change="columnsNoChange">
						<u-checkbox
							v-for="(item,index) in selectedOpItemPojo.mutiColCount"
							:key="index"
							:label="item"
							:name="item"
							:customStyle="checkboxCustomStyle">
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-line :customStyle="{marginTop:'5px'}"></u-line>
				<!-- 输入部位 -->
				<u-form-item
					v-show="show.partItem"
					label="设备部位"
					prop="partArr"
					ref="part">
					<u-checkbox-group
						v-model="formData.partArr"
						placement="column"
						@change="partChange">
						<u-checkbox
							v-for="(item,index) in selectedOpItemPojo.partAllArr"
							:key="index"
							:label="item.partName"
							:name="item.partName"
							:customStyle="checkboxCustomStyle2">
						</u-checkbox>
					</u-checkbox-group>
				</u-form-item>
				<u-line
					v-show="show.partItem"
					:customStyle="{marginTop:'5px'}">
				</u-line>
				<!-- 扫描LOT信息 -->
				<u-form-item
					label="LOT信息"
					prop="lotInfo"
					ref="lotInfo">
					<u--textarea
						v-model="formData.lotInfo"
						placeholder="按需输入或扫描"
						autoHeight
						count
						:maxlength="144">
						
					</u--textarea>
				</u-form-item>
				
				<!-- AQR信息记录 -->
				<u-form-item
					v-show="show.AQR"
					label="AQR信息"
					prop="AQRInfo"
					ref="AQRInfo">
					<u--textarea
						v-model="formData.AQRInfo"
						placeholder="按需输入或扫描"
						autoHeight
						count
						:maxlength="144">
						
					</u--textarea>
				</u-form-item>
				
				<!-- 输入备注 -->
				<u-form-item
					label="备注"
					prop="remark"
					ref="remark">
					<u--textarea
						v-model="formData.remark"
						placeholder="按需输入"
						autoHeight
						count
						:maxlength="144">
						
					</u--textarea>
				</u-form-item>
				<!-- 输入确认者 -->
				<u-form-item
					label="确认"
					prop="operationVerify"
					ref="operationVerify">
					<u-input
						v-model="formData.operationVerify"
						clearable
						placeholder="按需输入确认者姓名或账号">
						
					</u-input>
				</u-form-item>
				
			</u--form>
			<!-- 按钮 -->
			<u-button
				type="primary"
				:text="submitBtn.text"
				:loading="submitBtn.loading"
				customStyle="margin-top: 20px"
				loadingMode="semicircle"
				@click="formSubmit">
			</u-button>
			
			<u-button
				type="warning"
				:text="delBtn.text"
				:loading="delBtn.loading"
				plain
				loadingMode="semicircle"
				customStyle="margin-top: 20px"
				@click="formDel">
			</u-button>
			
			<!-- 开始时间选择器 -->
			<u-datetime-picker
				v-model="formData.timeInfo.begin"
				:show="show.timePicker.begin"
				mode="datetime"
				closeOnClickOverlay
				:minDate="beginTimePickerMinDate"
				:formatter="timePickerFormatter"
				@cancel="show.timePicker.begin=false"
				@close="show.timePicker.begin=false"
				@confirm="beginTimePickerConfirm"
				ref='beginTimePicker'
			></u-datetime-picker>
			<!-- 结束时间选择器 -->
			<u-datetime-picker
				v-model="formData.timeInfo.end"
				:show="show.timePicker.end"
				mode="datetime"
				:formatter="timePickerFormatter"
				closeOnClickOverlay
				:minDate="endTimePickerMinDate"
				@cancel="show.timePicker.end=false"
				@close="show.timePicker.end=false"
				@confirm="endTimePickerConfirm"
			></u-datetime-picker>
			
		</view>
	</view>
</template>

<script>
	import {getRecordByRecordID,uptRecordByRecordID,delRecordByRecordID} from '@/api/record/record.js'
	import {getOpitemByOpItemNameAndMachineNo} from '@/api/opitem/optiem.js'
	import {getMaintsItemByOpItemNameAndMachineNo} from '@/api/maintsitem/maintsitem.js';
	import {getAbnormalItemByOpItemNameAndMachineNo} from '@/api/abnormal/abnormal.js';
	import {getPartByMachineNo} from '@/api/part/part.js'
	import {getQrType} from '@/api/qrtype/qrtype.js'
	export default {
		data() {
			return {
				prePageOption:null,  // 上一页传过来的参数
				formData:{
					userCode:'',
					machineNo:'',
					opItemName:'',
					recordValue:'',
					timeInfo:{
						begin: uni.$u.timeFormat(Number(new Date()),'yyyy-mm-dd hh:MM'),
						end: uni.$u.timeFormat(Number(new Date())+60000,'yyyy-mm-dd hh:MM')
					},
					checkboxColumnsNoArr:[],
					partItem:[],
					lotInfo:'',
					remark:'',
					operationVerify:'',
					AQRInfo:''
					
				},
				formRules:{
					userCode:[
						{
							type: 'string',
							required: true,
							message: '请填写姓名',
							trigger: ['blur', 'change'],
						},
					],
					machineNo:[
						{
							type: 'string',
							required: true,
							message: '请填写设备号',
							trigger: ['blur', 'change']
						},
					],
					opItemName:[
						{
							required: true, 
							message: '不能为空',
							trigger: ['change','blur'],
						},
					],
					recordValue:[
						{
							required: true, 
							message: '不能为空',
							trigger: ['change','blur'],
						},
					],
					// 记录开始时间
					'timeInfo.begin':[
						{
							type: 'string',
							required: true,
							message: '请填写记录开始时间',
							trigger: ['blur']
						},
					],
					// 记录结束时间
					'timeInfo.end':[
						{
							type: 'string',
							required: true,
							message: '请填写记录结束时间',
							trigger: ['blur','change']
						},
						{
							validator: (rule,value,callback)=>{
								let begintime=this.formData.timeInfo.begin
								let endtime=value
								// 当时间不是时间戳时(非数字时)
								if(!(/^[0-9]+.?[0-9]*$/.test(begintime))){
									begintime = Number(new Date(begintime))
								}
								if(!(/^[0-9]+.?[0-9]*$/.test(endtime))){
									endtime = Number(new Date(endtime))
								}
								if(endtime>begintime){
									return true
								}
								return false
							},
							message: '结束时间不能小于开始时间',
						}
					],
					
				},
				formItemRecordLabel:'',
				selectedOpItemPojo:{},
				echo:{
					qrPn:'',
					qrLotNo:''
				},
				//qrtype的原型
				qrType:{},
				// 作业时多选时的数组
				checkboxOpRecordValueArr:[],
				show:{
					formItemShow:{
						recordItemInner:{
							textarea:false,
							input:false,
							radio:false,
							checkbox:false
						},
						abHandle: false,
						
					},
					timePicker:{
						begin:false,
						end:false,
					},
					columnsNo:false,
					partItem:false
				},
				// checkbox样式
				checkboxCustomStyle:{
					marginBottom:'0px'
				},
				checkboxCustomStyle2:{
					marginBottom:'0px'
				},
				recordSelectCustomStyle:{
					marginLeft:'80px',
					marginBottom: '0px'
				},
				abHandleCustomStyle:{
					marginBottom:'0px'
				},
				checkboxAbHandleValueArr:[],
				submitBtn:{
					text:'提交更新',
					loading:false,
					disabled:false
				},
				delBtn:{
					text:'删除记录',
					loading:false
				}
			}
		},
		computed:{
			beginTimePickerMinDate(){
				return 1672502400000
			},
			endTimePickerMinDate(){
				return (new Date(this.formData.timeInfo.begin).getTime())+60000
			},

		},
		onLoad(option) {
			//debug 71 单选
			//debug 75 多选
			//debug 76 文本
			//debug 74 扫描
			// option.recordID=78
			this.prePageOption=option
		},
		onReady(){
			const _this = this
			this.getOldData(this.prePageOption.recordID)
		},
		onNavigationBarButtonTap(e) {
			if (e.type === 'menu') {
				// this.showMenuDrawer();
			} else if (e.type === 'home') {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			}
		},
		methods: {
			async getOldData(recordID){
				const _this=this
				// 通过recordID获取record
				let {data} = await getRecordByRecordID({recordID:recordID}).catch(err=>{
					uni.showToast({
						title:err.msg|| '获取数据异常',
						icon:'error',
						duration:2000
					})
					uni.$u.sleep(2000).then(()=>{
						uni.navigateBack();
					})
					return 
				})
				console.log(data);
				this.formData.userCode=data.userCodeEnd || data.userCode
				this.formData.machineNo=data.machineNo
				this.formData.opItemName=data.recordName
				this.formData.recordValue=data.recordResult
				this.formData.lotInfo=(uni.$u.test.isEmpty(data.recordLotInfo)?'':data.recordLotInfo)
				this.formData.remark= (uni.$u.test.isEmpty(data.recordRemark)?'':data.recordRemark)
				this.formData.operationVerify=(uni.$u.test.isEmpty(data.recordVerify)?'':data.recordVerify) 
				//算时间
				// 获取时区的差
				// let utcTimeOffset = new Date().getTimezoneOffset()
				// if(utcTimeOffset!=(-480)){
				// 	data.recordTimeBegin=data.recordTimeBegin+(utcTimeOffset-480)*60000
				// 	data.recordTimeEnd=data.endtime+(utcTimeOffset-480)*60000
				// }
				this.$nextTick().then(()=>{
					this.formData.timeInfo.begin=uni.$u.timeFormat(data.recordTimeBeginDT,'yyyy-mm-dd hh:MM')
					this.formData.timeInfo.end=uni.$u.timeFormat(data.recordTimeEndDT,'yyyy-mm-dd hh:MM')
				})
					
				
				// op作业时
				if(data.recordType.includes('op')){
					this.showOpRecordItem(data)
				} else if (data.recordType.includes('保全')){
					// 去保全作业查找
					this.showMaintsRecordItem(data)
				} else if (data.recordType.includes('异常')){
					// 去异常查找
					this.showAbnormalRecordItem(data)
				} else{		// 错误值
					uni.showToast({
						title:'系统设定数据异常',
						icon:'error',
						duration:2000
					})
					uni.$u.sleep(2000).then(()=>{
						uni.navigateBack();
					})
					return 
				}
			},
			// 文本输入框失焦事件
			textInputItemBlur(val){
				console.log(val);
				
				if(uni.$u.test.isEmpty(this.selectedOpItemPojo.qrType)){
					uni.showToast({
						title:'系统设定异常',
						icon:'error'
					})
					return ;
				}
				getQrType({qrTypeID:this.selectedOpItemPojo.qrTypeID})
					.then(res=>{
						this.qrType=res.data
						if(uni.$u.test.isEmpty(this.formData.recordValue)){return}
						this.formData.recordValue=val.substr(this.qrType.pnFrom,this.qrType.pnLength).trim() + " | "+ val.substr(this.qrType.lotNoFrom,this.qrType.lotNoLength).trim()
						// this.disabled.textInputItem= true
						this.echo.qrPn="型名: " + val.substr(this.qrType.pnFrom,this.qrType.pnLength).trim()
						this.echo.qrLotNo="LotNo: " + val.substr(this.qrType.lotNoFrom,this.qrType.lotNoLength).trim() 
					})
					.catch(err=>{
						uni.showToast({
							title:err.msg,
							icon:'error'
						})
						return
					})		
			},
			radioChange(selected){
				this.formData.recordValue=selected
			},
			checkboxChange(selected){
				this.checkboxOpRecordValueArr=selected
				this.formData.recordValue=this.checkboxOpRecordValueArr.join(';')
			},
			/**
			 * 时间选择器
			 */
			timePickerFormatter(type,value){
				if (type === 'year') {
					return `${value}年`
				}
				if (type === 'month') {
					return `${value}月`
				}
				if (type === 'day') {
					return `${value}日`
				}
				if (type === 'hour'){
					return `${value}点`
				}
				if (type === 'minute'){
					return `${value}分`
				}
				
				return value
			},
			beginTimePickerConfirm(e){
				this.$nextTick(()=>{
					this.formData.timeInfo.begin=uni.$u.timeFormat(e.value,'yyyy-mm-dd hh:MM')
					
				})
				this.show.timePicker.begin=false
			},
			endTimePickerConfirm(e){
			
				this.$nextTick(()=>{
					this.formData.timeInfo.end=uni.$u.timeFormat(e.value,'yyyy-mm-dd hh:MM')
				})
				this.show.timePicker.end=false
				this.$refs.form.validateField('timeInfo.end')
			},
			columnsNoChange(selected){
				this.formData.checkboxColumnsNoArr=selected
				// this.formData.columnsNoValue=this.checkboxColumnsNoArr.join(';')
			},
			partChange(selected){
				this.formData.partArr=selected
			},
			hideKeyboard(){
				// #ifdef APP-PLUS
				uni.hideKeyboard()
				// #endif
			},
			async showOpRecordItem(data){
				// 去op作业查找设定
				let data2 = await getOpitemByOpItemNameAndMachineNo({opItemName:data.recordName,machineNo:data.machineNo}).catch(err=>{
					uni.showToast({
						title:err.msg|| '获取设定异常',
						icon:'error',
						duration:2000
					})
					uni.$u.sleep(2000).then(()=>{
						uni.navigateBack();
					})
					return 				
				})
				this.selectedOpItemPojo=data2.data;
				console.log(this.selectedOpItemPojo);
				// 列设定
				this.show.columnsNo=true
				// 设置选择列的格式
				if(!(uni.$u.test.isEmpty(this.selectedOpItemPojo.mutiColCount*1))){
					
					// 当选择列条数大于1时
					if((this.selectedOpItemPojo.mutiColCount*1)>1) {
						this.checkboxCustomStyle.marginBottom='8px'
					} else {
						this.checkboxCustomStyle.marginBottom='0px'
					}
				
					let tempArr=[]
					for(let i=0;i<this.selectedOpItemPojo.mutiColCount;i++){
						tempArr.push('第'+(i+1)+'列')
					}
					this.selectedOpItemPojo.mutiColCount=tempArr
					this.formData.checkboxColumnsNoArr=(uni.$u.test.isEmpty(data.recordSelectedColNo)?[]:data.recordSelectedColNo.split(';'))
						
				}
				// 设备部位设定
				this.show.partItem=true
				// 设备部位
				let temppart=await getPartByMachineNo({machineNo:this.formData.machineNo}).catch(err=>{
					this.show.partItem=false	
				})
				this.selectedOpItemPojo.partAllArr=temppart.data
				if(uni.$u.test.array(this.selectedOpItemPojo.partAllArr) && this.selectedOpItemPojo.partAllArr.length>1) {
					this.checkboxCustomStyle2.marginBottom='8px'
				} else {
					this.checkboxCustomStyle2.marginBottom='0px'
				}
				this.$nextTick(()=>{
					this.formData.partArr= (uni.$u.test.isEmpty(data.recordPart)?[]:data.recordPart.split(';')) 
				})
					
				// 记录方法
				// 如果记录方法是文本时
				if(this.selectedOpItemPojo.opItemContentType=='text'){
					// input项的label赋值
					this.formItemRecordLabel=this.selectedOpItemPojo.opItemContent
					if(this.selectedOpItemPojo.qrType=="textstr"){  //文本输入
						this.show.formItemShow.recordItemInner.textarea=true
						this.formData.recordValue=data.recordResult
					} else {	//扫描输入
						this.show.formItemShow.recordItemInner.input=true
						this.formData.recordValue=data.recordResult
					}
				}
				// 如果记录方法是单选或多选
				// else if(this.selectedOpItemPojo.opItemContentType=='select'){
				else {
					if(uni.$u.test.isEmpty(this.selectedOpItemPojo.opItemContent)){
						uni.showToast({
							title:'系统设定异常',
							icon:'error'
						})
						uni.$u.sleep(1500).then(()=>{
							return
						})
					}
					// 按;分割字符串
					this.selectedOpItemPojo.opItemContent = this.selectedOpItemPojo.opItemContent.split(/;|；/i)
				
					if(this.selectedOpItemPojo.opItemContentType=='select'){		//单选
						uni.$u.sleep(50).then(()=>{
							this.formData.recordValue=data.recordResult
							this.show.formItemShow.recordItemInner.radio=true
						})
					} else {  //多选
						uni.$u.sleep(50).then(()=>{
							// this.checkboxOpRecordValueArr=[this.selectedOpItemPojo.opItemContent[0]]
							this.checkboxOpRecordValueArr=data.recordResult.split(';')
							this.show.formItemShow.recordItemInner.checkbox=true
						})
					}
				}
			},
			async showMaintsRecordItem(data){
				// 去保全作业查找设定
				let data2 = await getMaintsItemByOpItemNameAndMachineNo({opItemName:data.recordName,machineNo:data.machineNo}).catch(err=>{
					uni.showToast({
						title:err.msg|| '获取设定异常',
						icon:'error',
						duration:2000
					})
					uni.$u.sleep(2000).then(()=>{
						uni.navigateBack();
					})
					return 				
				})
				this.selectedOpItemPojo=data2.data;
				console.log(this.selectedOpItemPojo);
				// 列设定
				this.show.columnsNo=true
				// 设置选择列的格式
				if(!(uni.$u.test.isEmpty(this.selectedOpItemPojo.mutiColCount*1))){
					
					// 当选择列条数大于1时
					if((this.selectedOpItemPojo.mutiColCount*1)>1) {
						this.checkboxCustomStyle.marginBottom='8px'
					} else {
						this.checkboxCustomStyle.marginBottom='0px'
					}
				
					let tempArr=[]
					for(let i=0;i<this.selectedOpItemPojo.mutiColCount;i++){
						tempArr.push('第'+(i+1)+'列')
					}
					this.selectedOpItemPojo.mutiColCount=tempArr
					this.formData.checkboxColumnsNoArr=(uni.$u.test.isEmpty(data.recordSelectedColNo)?[]:data.recordSelectedColNo.split(';'))
						
				}
				// 设备部位设定
				this.show.partItem=true
				// 设备部位
				let temppart=await getPartByMachineNo({machineNo:this.formData.machineNo}).catch(err=>{
					this.show.partItem=false	
				})
				this.selectedOpItemPojo.partAllArr=temppart.data
				if(uni.$u.test.array(this.selectedOpItemPojo.partAllArr) && this.selectedOpItemPojo.partAllArr.length>1) {
					this.checkboxCustomStyle2.marginBottom='8px'
				} else {
					this.checkboxCustomStyle2.marginBottom='0px'
				}
				this.$nextTick(()=>{
					this.formData.partArr=(uni.$u.test.isEmpty(data.recordPart)?[]:data.recordPart.split(';'))
				})
					
				// 记录方法
				// 如果记录方法是文本时
				if(this.selectedOpItemPojo.maintsItemContentType=='text'){
					// input项的label赋值
					this.formItemRecordLabel=this.selectedOpItemPojo.maintsItemContent
					if(this.selectedOpItemPojo.qrType=="textstr"){  //文本输入
						this.show.formItemShow.recordItemInner.textarea=true
						this.formData.recordValue=data.recordResult
					} else {	//扫描输入
						this.show.formItemShow.recordItemInner.input=true
						this.formData.recordValue=data.recordResult
					}
				}
				// 如果记录方法是单选或多选
				// else if(this.selectedOpItemPojo.opItemContentType=='select'){
				else {
					if(uni.$u.test.isEmpty(this.selectedOpItemPojo.maintsItemContent)){
						uni.showToast({
							title:'系统设定异常',
							icon:'error'
						})
						uni.$u.sleep(1500).then(()=>{
							return
						})
					}
					// 按;分割字符串
					this.selectedOpItemPojo.opItemContent = this.selectedOpItemPojo.maintsItemContent.split(/;|；/i)
					
					if(this.selectedOpItemPojo.maintsItemContentType=='select'){		//单选
						uni.$u.sleep(50).then(()=>{
							this.formData.recordValue=data.recordResult
							this.show.formItemShow.recordItemInner.radio=true
						})
					} else {  //多选
						uni.$u.sleep(50).then(()=>{
							// this.checkboxOpRecordValueArr=[this.selectedOpItemPojo.opItemContent[0]]
							this.checkboxOpRecordValueArr=data.recordResult.split(';')
							console.log(this.checkboxOpRecordValueArr);
							this.show.formItemShow.recordItemInner.checkbox=true
						})
					}
				}
			},
			async showAbnormalRecordItem(data){
				// 去保全作业查找设定
				let data2 = await getAbnormalItemByOpItemNameAndMachineNo({opItemName:data.recordName,machineNo:data.machineNo}).catch(err=>{
					uni.showToast({
						title:err.msg|| '获取设定异常',
						icon:'error',
						duration:2000
					})
					uni.$u.sleep(2000).then(()=>{
						uni.navigateBack();
					})
					return 				
				})
				this.selectedOpItemPojo=data2.data;
				console.log(this.selectedOpItemPojo);
				
				// this.formItemRecordLabel='异常内容'
				if(!uni.$u.test.isEmpty(this.selectedOpItemPojo.abHandleList)){
					 let tmpArr23=[]
					 this.selectedOpItemPojo.abHandleList.forEach(item=>{
						 tmpArr23.push(item.abHandleItemName)
					 })
					this.selectedOpItemPojo.abHandleList=tmpArr23
				}
				// this.selectedOpItemPojo.abHandleList= this.selectedOpItemPojo.abHandleList.split(/;|；/i)

				// 按;分割字符串
				this.selectedOpItemPojo.opItemContent = this.selectedOpItemPojo.abnormalItem.abnormalItemContent.split(/;|；/i)
				if(uni.$u.test.array(this.selectedOpItemPojo.opItemContent) && this.selectedOpItemPojo.opItemContent.length>1){
					// this.recordSelectCustomStyle.marginLeft='80px'
					this.recordSelectCustomStyle.marginBottom='10px'
				}
								
				if(uni.$u.test.array(this.selectedOpItemPojo.abHandleList) && this.selectedOpItemPojo.abHandleList.length>1){
					// this.recordSelectCustomStyle.marginLeft='80px'
					this.abHandleCustomStyle.marginBottom='10px'
				}
				uni.$u.sleep(50).then(()=>{
					this.checkboxAbHandleValueArr=[this.selectedOpItemPojo.abHandleList[0]]
					// 默认值
					this.checkboxOpRecordValueArr=data.recordResult.split(';')
					this.checkboxAbHandleValueArr=data.abnormalHandler.split(';')
					this.formData.recordValue=this.checkboxOpRecordValueArr.join(';')
					this.formData.abHandleValue= this.checkboxAbHandleValueArr.join(';')
					this.show.formItemShow.recordItemInner.checkbox=true
					this.show.formItemShow.abHandle=true
				})
				this.show.AQR=true
				this.formData.AQRInfo=(uni.$u.test.isEmpty(data.recordAQRInfo)?'':data.recordAQRInfo)
			},
			checkboxAbHandleChange(selected){
				this.checkboxAbHandleValueArr=selected
				this.formData.abHandleValue=this.checkboxAbHandleValueArr.join(';')
				
			},
			formSubmit(){
				const _this= this
				// let begintime = (/^[0-9]+.?[0-9]*$/.test(this.formData.timeInfo.begin))?this.formData.timeInfo.begin:new Date(this.formData.timeInfo.begin).getTime()
				// let endtime = (/^[0-9]+.?[0-9]*$/.test(this.formData.timeInfo.end))?this.formData.timeInfo.end:new Date(this.formData.timeInfo.end).getTime()

				let begintime = uni.$u.timeFormat(this.formData.timeInfo.begin,'yyyy-mm-dd hh:MM:ss')   
				let endtime = uni.$u.timeFormat(this.formData.timeInfo.end,'yyyy-mm-dd hh:MM:ss')
				
				// 获取时区的差
				// let utcTimeOffset = new Date().getTimezoneOffset()
				// if(utcTimeOffset!=(-480)){
				// 	begintime=begintime+(utcTimeOffset-480)*60000
				// 	endtime=endtime+(utcTimeOffset-480)*60000
				// }
				this.$refs.form.validate().then(res=>{
					console.log(res);
					const data= {
						recordID:this.prePageOption.recordID,
						userCode:this.formData.userCode,
						userCodeEnd:this.formData.userCode,
						machineNo:this.formData.machineNo,
						recordResult:this.formData.recordValue,
						recordPart: uni.$u.test.isEmpty(this.formData.partArr)?'':this.formData.partArr.join(';'),
						abnormalHandler:this.formData.abHandleValue,
						recordTimeBeginDT:begintime,
						recordTimeEndDT:endtime,
						recordSelectedColNo:uni.$u.test.isEmpty(this.formData.checkboxColumnsNoArr)?'':this.formData.checkboxColumnsNoArr.join(';'),
						recordLotInfo: this.formData.lotInfo,
						recordAQRInfo: this.formData.AQRInfo,
						recordRemark: this.formData.remark,
						recordVerify:this.formData.operationVerify
					}
					uni.showModal({
						title:'更新',
						content: '确认更新吗?',
						success(res) {
							if(res.confirm){
								_this.submitBtn.text="上传中..."
								_this.submitBtn.loading=true		
								uptRecordByRecordID(data).then(res=>{
									uni.showToast({
										title:'更新成功',
										duration:2000
									})						
									uni.$u.sleep(2000).then(()=>{
										uni.redirectTo({
											url:"/pages/index/index"
										})
									})
								}).catch(err=>{
									uni.showToast({
										title: err.msg,
										icon:'error',
										duration:2000
									})
								}).finally(()=>{
									_this.submitBtn.text="提交更新"
									_this.submitBtn.loading=false	
								})
							}
						}
					})
				}).catch(err=>{
					console.log(err);
					uni.showToast({
						title:'提交数据错误',
						icon:'error',
						duration:2000
					})
				})
				
			},
			formDel(){
				const _this= this
				uni.showModal({
					title:'删除',
					content: '确认删除吗?',
					success(res) {
						if(res.confirm){
							_this.delBtn.text="上传中..."
							_this.delBtn.loading=true		
							
							delRecordByRecordID({recordID:_this.prePageOption.recordID}).then(res=>{
								uni.showToast({
									title:'删除成功',
									duration:2000
								})						
								uni.$u.sleep(2000).then(()=>{
									uni.redirectTo({
										url:"/pages/index/index"
									})
								})
							}).catch(err=>{
								uni.showToast({
									title: err.msg,
									icon:'error',
									duration:2000
								})
							}).finally(()=>{
								_this.delBtn.text="删除记录"
								_this.delBtn.loading=false	
							})
						}
					}
				})
			},
		}

	}
</script>

<style lang="scss" scoped>
.echo {
	margin-left: 80px;
}
</style>
